package com.zp.self.module.level_5_设计模式.行为型模式.Ⅳ_责任链模式;

/**
 * @version v1.0
 * @ClassName: Handler
 * @Description: 抽象处理者类
 * @Author: 黑马程序员
 */
public abstract class Handler {

    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    //该领导处理的请求天数区间
    private int handlerDayNum;

    //声明后续者（声明上级领导）
    private Handler nextHandler;

    public Handler(int numStart) {
        this.handlerDayNum = numStart;
    }

    //设置上级领导对象
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    //各级领导处理请求条的方法
    protected abstract void handleLeave(LeaveRequest leave);

    //提交请求条。假设：这个码农每天工作12个小时，表现良好，到领导那个都能正常通过
    public final void submit(LeaveRequest leave) {
        //当前领导审批条件：numStart < leave.getNum()
        if(handlerDayNum < leave.getNum() ) {
            //该领导进行审批
            this.handleLeave(leave);
        }
        //提交给上级领导进行审批
        if(nextHandler!=null){
            this.nextHandler.submit(leave);
        }else{
            System.out.println("流程结束");
        }
    }
}
